package com.tangsm.spring.boot.validation.controller;

import com.tangsm.spring.boot.validation.exception.BusinessException;
import com.tangsm.spring.boot.validation.enums.ResultStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 自定义异常测试
 * @author tangsm
 */
@RestController
@RequestMapping("/exce")
public class ExceptionDemoController {
    private static final Logger log = LoggerFactory.getLogger(ExceptionDemoController.class);

    /**
     * 测试BusinessException自定义异常
     * @throws BusinessException 异常
     */
    @GetMapping("/business")
    public void business() throws BusinessException{
        log.info("测试BusinessException自定义异常");
        throw new BusinessException();
    }

    /**
     * 测试BusinessException自定义异异常，传参异常枚举
     * @throws BusinessException 异常
     */
    @GetMapping("/businessResultStatus")
    public void businessResultStatus() throws BusinessException{
        log.info("测试BusinessException自定义异异常，传参异常枚举");
        throw new BusinessException(ResultStatus.TEST_ERROR);
    }

    /**
     * 测试RuntimeException异常
     * @throws RuntimeException 异常
     */
    @GetMapping("/runtime")
    public void runtime() throws RuntimeException{
        log.info("测试RuntimeException异常");
        throw new RuntimeException(ResultStatus.TEST_ERROR.getMsg());
    }

    /**
     * 测试Exception异常
     * @throws Exception 异常
     */
    @GetMapping("/exception")
    public void exception() throws Exception{
        log.info("测试Exception异常");
        throw new Exception(ResultStatus.TEST_ERROR.getMsg());
    }
}
